// RealPlay Ltd  copyrights.
// This program is Open Source AsIs
// You may use it for all purposes, including commercial
// But!!!
// If you use any part of this code, you must state clearly
// both in your source file and in the Help|about of your program,
// that the origin program or code was built by RealPlay Ltd

// ***********************************************************************/
// *                                                                     */
// *     This unit is frame for tools options in "Paint" Program         */
// *                                                                     */
// ***********************************************************************/

unit UPFrToolOptions;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Buttons;

const
  // toNoTransparancy = 1;
  // toTransparancy = 2;
  toEraseSize1 = 1;
  toEraseSize2 = 2;
  toEraseSize3 = 3;
  toEraseSize4 = 4;
  toMagnifySize1 = 1;
  toMagnifySize2 = 2;
  toMagnifySize3 = 3;
  toMagnifySize4 = 4;
  toBrush1 = 1;
  toBrush2 = 2;
  toBrush3 = 3;
  toBrush4 = 4;
  toBrush5 = 5;
  toBrush6 = 6;
  toBrush7 = 7;
  toBrush8 = 8;
  toBrush9 = 9;
  toBrush10 = 10;
  toBrush11 = 11;
  toBrush12 = 12;
  toSpray1 = 1;
  toSpray2 = 2;
  toSpray3 = 3;
  toLine1 = 1;
  toLine2 = 2;
  toLine3 = 3;
  toLine4 = 4;
  toLine5 = 5;
  toRect1 = 1;
  toRect2 = 2;
  toRect3 = 3;

type
  TFrameToolOption = class(TFrame)
    PanelToolOption: TPanel;
    ImageNoTransparancy: TImage;
    ImageTransparancy: TImage;
    ImageEraseSize1: TImage;
    ImageEraseSize2: TImage;
    ImageEraseSize3: TImage;
    ImageEraseSize4: TImage;
    ImageMagnify1: TImage;
    ImageMagnify2: TImage;
    ImageMagnify3: TImage;
    ImageMagnify4: TImage;
    ImageBrush1: TImage;
    ImageBrush2: TImage;
    ImageBrush3: TImage;
    ImageBrush4: TImage;
    ImageBrush5: TImage;
    ImageBrush6: TImage;
    ImageBrush7: TImage;
    ImageBrush8: TImage;
    ImageBrush9: TImage;
    ImageBrush10: TImage;
    ImageBrush11: TImage;
    ImageBrush12: TImage;
    ImageSpray1: TImage;
    ImageSpray2: TImage;
    ImageSpray3: TImage;
    ImageLine1: TImage;
    ImageLine2: TImage;
    ImageLine3: TImage;
    ImageLine4: TImage;
    ImageLine5: TImage;
    ImageRect1: TImage;
    ImageRect2: TImage;
    ImageRect3: TImage;
    procedure ImageNoTransparancyClick(Sender: TObject);
    procedure ImageTransparancyClick(Sender: TObject);
    procedure SetTool(tool: Integer);
    procedure ImageEraseSizeClick(Sender: TObject);
    procedure ImageMagnifyClick(Sender: TObject);
    procedure ImageBrushClick(Sender: TObject);
    procedure ImageSprayClick(Sender: TObject);
    procedure ImageLineClick(Sender: TObject);
    procedure ImageRectClick(Sender: TObject);
  private
    { Private declarations }
    procedure CleanTools;
    procedure TransparancyTools;
    procedure EraserTools;
    procedure MagnifyTools;
    procedure BrushTools;
    procedure SprayTools;
    procedure LineTools;
    procedure RectTools;
  public
    { Public declarations }
    TransparentState: Boolean;
    EraseSizeState: Integer;
    MagnifySizeState: Integer;
    BrushState: Integer;
    SprayState: Integer;
    LineState: Integer;
    RectState: Integer;
    constructor create(AOwner: TComponent); override;
  end;

implementation

uses UPUtil, UPMain;
{$R *.dfm}

constructor TFrameToolOption.create;
begin
  inherited create(AOwner);
  TransparentState := false;
end;

procedure TFrameToolOption.CleanTools;
begin
  ImageNoTransparancy.visible := false;
  ImageTransparancy.visible := false;
  ImageEraseSize1.visible := false;
  ImageEraseSize2.visible := false;
  ImageEraseSize3.visible := false;
  ImageEraseSize4.visible := false;
  ImageMagnify1.visible := false;
  ImageMagnify2.visible := false;
  ImageMagnify3.visible := false;
  ImageMagnify4.visible := false;
  ImageBrush1.visible := false;
  ImageBrush2.visible := false;
  ImageBrush3.visible := false;
  ImageBrush4.visible := false;
  ImageBrush5.visible := false;
  ImageBrush6.visible := false;
  ImageBrush7.visible := false;
  ImageBrush8.visible := false;
  ImageBrush9.visible := false;
  ImageBrush10.visible := false;
  ImageBrush11.visible := false;
  ImageBrush12.visible := false;
  ImageSpray1.visible := false;
  ImageSpray2.visible := false;
  ImageSpray3.visible := false;
  ImageLine1.visible := false;
  ImageLine2.visible := false;
  ImageLine3.visible := false;
  ImageLine4.visible := false;
  ImageLine5.visible := false;
  ImageRect1.visible := false;
  ImageRect2.visible := false;
  ImageRect3.visible := false;
end;

procedure TFrameToolOption.TransparancyTools;
begin
  ImageNoTransparancy.visible := true;
  ImageTransparancy.visible := true;
  if ImageTransparancy.Transparent then
    TransparentState := false
  else
    TransparentState := true;
end;

procedure TFrameToolOption.EraserTools;
begin
  ImageEraseSize1.visible := true;
  ImageEraseSize2.visible := true;
  ImageEraseSize3.visible := true;
  ImageEraseSize4.visible := true;
  if not ImageEraseSize1.Transparent then
  begin
    EraseSizeState := toEraseSize1;
    BlackToWhite(ImageEraseSize1);
  end;
  if not ImageEraseSize2.Transparent then
  begin
    EraseSizeState := toEraseSize2;
    BlackToWhite(ImageEraseSize2);
  end;
  if not ImageEraseSize3.Transparent then
  begin
    EraseSizeState := toEraseSize3;
    BlackToWhite(ImageEraseSize3);
  end;
  if not ImageEraseSize4.Transparent then
  begin
    EraseSizeState := toEraseSize4;
    BlackToWhite(ImageEraseSize4);
  end;
end;

procedure TFrameToolOption.MagnifyTools;
begin
  ImageMagnify1.visible := true;
  ImageMagnify2.visible := true;
  ImageMagnify3.visible := true;
  ImageMagnify4.visible := true;
  if not ImageMagnify1.Transparent then
  begin
    MagnifySizeState := toMagnifySize1;
    BlackToWhite(ImageMagnify1);
  end;
  if not ImageMagnify2.Transparent then
  begin
    MagnifySizeState := toMagnifySize2;
    BlackToWhite(ImageMagnify2);
  end;
  if not ImageMagnify3.Transparent then
  begin
    MagnifySizeState := toMagnifySize3;
    BlackToWhite(ImageMagnify3);
  end;
  if not ImageMagnify4.Transparent then
  begin
    MagnifySizeState := toMagnifySize4;
    BlackToWhite(ImageMagnify4);
  end;
end;

procedure TFrameToolOption.BrushTools;
begin
  ImageBrush1.visible := true;
  ImageBrush2.visible := true;
  ImageBrush3.visible := true;
  ImageBrush4.visible := true;
  ImageBrush5.visible := true;
  ImageBrush6.visible := true;
  ImageBrush7.visible := true;
  ImageBrush8.visible := true;
  ImageBrush9.visible := true;
  ImageBrush10.visible := true;
  ImageBrush11.visible := true;
  ImageBrush12.visible := true;
  if not ImageBrush1.Transparent then
  begin
    BrushState := toBrush1;
    BlackToWhite(ImageBrush1);
  end;
  if not ImageBrush2.Transparent then
  begin
    BrushState := toBrush2;
    BlackToWhite(ImageBrush2);
  end;
  if not ImageBrush3.Transparent then
  begin
    BrushState := toBrush3;
    BlackToWhite(ImageBrush3);
  end;
  if not ImageBrush4.Transparent then
  begin
    BrushState := toBrush4;
    BlackToWhite(ImageBrush4);
  end;
  if not ImageBrush5.Transparent then
  begin
    BrushState := toBrush5;
    BlackToWhite(ImageBrush5);
  end;
  if not ImageBrush6.Transparent then
  begin
    BrushState := toBrush6;
    BlackToWhite(ImageBrush6);
  end;
  if not ImageBrush7.Transparent then
  begin
    BrushState := toBrush7;
    BlackToWhite(ImageBrush7);
  end;
  if not ImageBrush8.Transparent then
  begin
    BrushState := toBrush8;
    BlackToWhite(ImageBrush8);
  end;
  if not ImageBrush9.Transparent then
  begin
    BrushState := toBrush9;
    BlackToWhite(ImageBrush9);
  end;
  if not ImageBrush10.Transparent then
  begin
    BrushState := toBrush10;
    BlackToWhite(ImageBrush10);
  end;
  if not ImageBrush11.Transparent then
  begin
    BrushState := toBrush11;
    BlackToWhite(ImageBrush11);
  end;
  if not ImageBrush12.Transparent then
  begin
    BrushState := toBrush12;
    BlackToWhite(ImageBrush12);
  end;
end;

procedure TFrameToolOption.SprayTools;
begin
  ImageSpray1.visible := true;
  ImageSpray2.visible := true;
  ImageSpray3.visible := true;
  if not ImageSpray1.Transparent then
  begin
    SprayState := toSpray1;
    BlackToWhite(ImageSpray1);
  end;
  if not ImageSpray2.Transparent then
  begin
    SprayState := toSpray2;
    BlackToWhite(ImageSpray2);
  end;
  if not ImageSpray3.Transparent then
  begin
    SprayState := toSpray3;
    BlackToWhite(ImageSpray3);
  end;
end;

procedure TFrameToolOption.LineTools;
begin
  ImageLine1.visible := true;
  ImageLine2.visible := true;
  ImageLine3.visible := true;
  ImageLine4.visible := true;
  ImageLine5.visible := true;
  if not ImageLine1.Transparent then
  begin
    LineState := toLine1;
    BlackToWhite(ImageLine1);
  end;
  if not ImageLine2.Transparent then
  begin
    LineState := toLine2;
    BlackToWhite(ImageLine2);
  end;
  if not ImageLine3.Transparent then
  begin
    LineState := toLine3;
    BlackToWhite(ImageLine3);
  end;
  if not ImageLine4.Transparent then
  begin
    LineState := toLine4;
    BlackToWhite(ImageLine4);
  end;
  if not ImageLine5.Transparent then
  begin
    LineState := toLine5;
    BlackToWhite(ImageLine5);
  end;
end;

procedure TFrameToolOption.RectTools;
begin
  ImageRect1.visible := true;
  ImageRect2.visible := true;
  ImageRect3.visible := true;
  if not ImageRect1.Transparent then
  begin
    RectState := toRect1;
    BlackToWhite(ImageRect1);
  end;
  if not ImageRect2.Transparent then
  begin
    RectState := toRect2;
    BlackToWhite(ImageRect2);
  end;
  if not ImageRect3.Transparent then
  begin
    RectState := toRect3;
    BlackToWhite(ImageRect3);
  end;
end;

procedure TFrameToolOption.SetTool(tool: Integer);
begin
  CleanTools;
  case tool of
    // it is importent to use the cobst and not the numbers because when changed
    // The program will still work properly
    crCatchS, crCatch:
      TransparancyTools;
    crMag:
      MagnifyTools;
    crPen, crLine, crCurve:
      LineTools;
    crBrush:
      BrushTools;
    crSpray:
      SprayTools;
    crRect, crRectS, crCircle, crCircleS:
      RectTools;
    crTrans:
      TransparancyTools;
    crErasor:
      EraserTools;
    {
      crErasor1
      crErasor2
      crErasor3
      }
  end;
end;

procedure TFrameToolOption.ImageNoTransparancyClick(Sender: TObject);
begin
  ImageNoTransparancy.Transparent := false;
  ImageTransparancy.Transparent := true;
  TransparentState := false;
end;

procedure TFrameToolOption.ImageTransparancyClick(Sender: TObject);
begin
  ImageNoTransparancy.Transparent := true;
  ImageTransparancy.Transparent := false;
  TransparentState := true;
end;

procedure TFrameToolOption.ImageEraseSizeClick(Sender: TObject);
begin
  ImageEraseSize1.Transparent := true;
  ImageEraseSize2.Transparent := true;
  ImageEraseSize3.Transparent := true;
  ImageEraseSize4.Transparent := true;
  case EraseSizeState of
    toEraseSize1:
      WhiteToBlack(ImageEraseSize1);
    toEraseSize2:
      WhiteToBlack(ImageEraseSize2);
    toEraseSize3:
      WhiteToBlack(ImageEraseSize3);
    toEraseSize4:
      WhiteToBlack(ImageEraseSize4);
  end;
  EraseSizeState := (Sender as TImage).Tag; (Sender as TImage)
  .Transparent := false;
  BlackToWhite((Sender as TImage));
end;

procedure TFrameToolOption.ImageMagnifyClick(Sender: TObject);
begin
  ImageMagnify1.Transparent := true;
  ImageMagnify2.Transparent := true;
  ImageMagnify3.Transparent := true;
  ImageMagnify4.Transparent := true;
  case MagnifySizeState of
    toMagnifySize1:
      WhiteToBlack(ImageMagnify1);
    toMagnifySize2:
      WhiteToBlack(ImageMagnify2);
    toMagnifySize3:
      WhiteToBlack(ImageMagnify3);
    toMagnifySize4:
      WhiteToBlack(ImageMagnify4);
  end;
  MagnifySizeState := (Sender as TImage).Tag;
  with fpaint.FWA do
  begin
    ZoomXr := MagnifySizeState;
    ZoomYr := MagnifySizeState;
    ImPanel.Height := trunc(IM.Picture.Bitmap.Height * ZoomYr)
      + ImBottomPanel.Height;
    ImPanel.Width := trunc(IM.Picture.Bitmap.Width * ZoomXr)
      + IMRightPanel.Width;
    MyStat.cx := ZoomXr;
    MyStat.cy := ZoomYr;
  end; (Sender as TImage)
  .Transparent := false;
  BlackToWhite(Sender as TImage);
end;

procedure TFrameToolOption.ImageBrushClick(Sender: TObject);
begin
  ImageBrush1.Transparent := true;
  ImageBrush2.Transparent := true;
  ImageBrush3.Transparent := true;
  ImageBrush4.Transparent := true;
  ImageBrush5.Transparent := true;
  ImageBrush6.Transparent := true;
  ImageBrush7.Transparent := true;
  ImageBrush8.Transparent := true;
  ImageBrush9.Transparent := true;
  ImageBrush10.Transparent := true;
  ImageBrush11.Transparent := true;
  ImageBrush12.Transparent := true;
  case BrushState of
    toBrush1:
      WhiteToBlack(ImageBrush1);
    toBrush2:
      WhiteToBlack(ImageBrush2);
    toBrush3:
      WhiteToBlack(ImageBrush3);
    toBrush4:
      WhiteToBlack(ImageBrush4);
    toBrush5:
      WhiteToBlack(ImageBrush5);
    toBrush6:
      WhiteToBlack(ImageBrush6);
    toBrush7:
      WhiteToBlack(ImageBrush7);
    toBrush8:
      WhiteToBlack(ImageBrush8);
    toBrush9:
      WhiteToBlack(ImageBrush9);
    toBrush10:
      WhiteToBlack(ImageBrush10);
    toBrush11:
      WhiteToBlack(ImageBrush11);
    toBrush12:
      WhiteToBlack(ImageBrush12);
  end;
  BrushState := (Sender as TImage).Tag; (Sender as TImage)
  .Transparent := false;
  BlackToWhite(Sender as TImage);
end;

procedure TFrameToolOption.ImageSprayClick(Sender: TObject);
begin
  ImageSpray1.Transparent := true;
  ImageSpray2.Transparent := true;
  ImageSpray3.Transparent := true;
  case SprayState of
    toSpray1:
      WhiteToBlack(ImageSpray1);
    toSpray2:
      WhiteToBlack(ImageSpray2);
    toSpray3:
      WhiteToBlack(ImageSpray3);
  end;
  SprayState := (Sender as TImage).Tag; (Sender as TImage)
  .Transparent := false;
  BlackToWhite(Sender as TImage);
end;

procedure TFrameToolOption.ImageLineClick(Sender: TObject);
begin
  ImageLine1.Transparent := true;
  ImageLine2.Transparent := true;
  ImageLine3.Transparent := true;
  ImageLine4.Transparent := true;
  ImageLine5.Transparent := true;
  case LineState of
    toLine1:
      WhiteToBlack(ImageLine1);
    toLine2:
      WhiteToBlack(ImageLine2);
    toLine3:
      WhiteToBlack(ImageLine3);
    toLine4:
      WhiteToBlack(ImageLine4);
    toLine5:
      WhiteToBlack(ImageLine5);
  end;
  LineState := (Sender as TImage).Tag; (Sender as TImage)
  .Transparent := false;
  BlackToWhite(Sender as TImage);
end;

procedure TFrameToolOption.ImageRectClick(Sender: TObject);
begin
  ImageRect1.Transparent := true;
  ImageRect2.Transparent := true;
  ImageRect3.Transparent := true;
  case RectState of
    toRect1:
      WhiteToBlack(ImageRect1);
    toRect2:
      WhiteToBlack(ImageRect2);
    toRect3:
      WhiteToBlack(ImageRect3);
  end;
  RectState := (Sender as TImage).Tag; (Sender as TImage)
  .Transparent := false;
  BlackToWhite(Sender as TImage);
end;

end.
